package com.avantis.common.repository;

import com.avantis.common.entity.AdminUser;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * @ClassName AdminUserRepository
 * @Description TODO
 * @Author kirago
 * @Date 2018/11/26 19:25
 * @Version 1.0
 **/
@Repository
@CacheConfig(cacheNames = "adminusers")
public interface AdminUserRepository extends JpaRepository<AdminUser, Integer>, JpaSpecificationExecutor {

	Optional<AdminUser> findById(Integer integer);

	@Cacheable
	List<AdminUser> findAll();

	AdminUser findByUsername(String username);

	AdminUser findByEmail(String email);

	@Query(value = "select * from k_adminuser where (userName=?1 or email=?1) and password=?2 " ,nativeQuery = true)
	AdminUser findByAccountAndPassword(String username,String password);

	@Cacheable
	@Override
	List findAll(Specification specification, Sort sort);
}
